package dao.impl;

import java.io.File;
import java.io.IOException;

import model.impl.VehiclesImpl;

import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.resotc.dao.VehiclesDAO;
import org.resotc.model.Vehicle;

public class VehiclesDAOImpl extends AbstractXMLDAO implements VehiclesDAO {
	private final static String indexFileName = "vehicles.xml";
	private int decisionmechanism;
	private int length;
	private VehiclesImpl vehiclesImpl;
	public VehiclesDAOImpl() throws JDOMException, IOException {
		indexFile = new File(rootPath + "/" + indexFileName);
		
		loadXML();
		parseXML();
	}

	public Vehicle getVehicle() {
		// TODO Auto-generated method stub
		return vehiclesImpl;
	}
	private void parseXML() {
		Element rootElement = indexXMLInstance.getRootElement();
		Element vehiclesElements = rootElement.getChild("vehicles");
		decisionmechanism = Integer.valueOf(vehiclesElements.getChildText("decisionmechanism"));
		length = Integer.valueOf(vehiclesElements.getChildText("length"));	
		vehiclesImpl = new VehiclesImpl(decisionmechanism,length);

	}
}